package xyz.xuminghai.javafx_learn.animation.transition;

import javafx.animation.Animation;
import javafx.animation.FillTransition;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import javafx.util.Duration;

/**
 * 2023/7/21 22:03 星期五<br/>
 * 此Transition创建一个动画，该动画在一段duration内改变形状的填充。
 * 这是通过定期更新shape的fill变量来完成的
 *
 * @author xuMingHai
 */
public class FillTransitionApp extends Application {

    private final BorderPane root = new BorderPane();

    public static void main(String[] args) {
        Application.launch(args);
    }

    @Override
    public void init() {
        Rectangle rectangle = new Rectangle(100.0, 100.0);

        FillTransition fillTransition = new FillTransition(Duration.millis(3000.0),
                rectangle, null, Color.BLUE);

        fillTransition.setCycleCount(Animation.INDEFINITE);
        fillTransition.setAutoReverse(true);
        fillTransition.play();

        root.setCenter(rectangle);
    }


    public void start(Stage primaryStage) {
        primaryStage.setTitle(getClass().getSimpleName());
        Scene scene = new Scene(root, 800, 600);
        primaryStage.setScene(scene);
        primaryStage.show();
    }

}
